package com.api.demo.test.business;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.api.demo.dto.business.worker.ApiAddWorkerDTO;
import com.api.demo.dto.business.worker.ApiWorkerAgreementDTO;
import com.api.demo.util.ApiSignUtil;
import com.api.demo.util.CommonUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 创客相关
 * @author: yanming
 * @createDate: 2022/12/26 14:27
 */
public class Worker {


    /**
     * 添加创客
     */
    public static String addWorkerPath = "%s/api/worker/add";

    /**
     * 查询创客合同
     */
    public static String getWorkerAgreementPath = "%s/api/worker/agreement";


    public static void main(String[] args) {

        /**
         * 添加创客
         */
        addWorker();

        /**
         * 查询创客合同
         */
        getWorkerAgreement();

    }

    /**
     * 添加创客
     */
    public static void addWorker() {
        ApiAddWorkerDTO apiAddWorkerDTO = new ApiAddWorkerDTO();
        apiAddWorkerDTO.setAgentId(CommonUtil.AGENT_ID);
        apiAddWorkerDTO.setTimestamp(System.currentTimeMillis());
        apiAddWorkerDTO.setCreditCode(CommonUtil.creditCode);
        apiAddWorkerDTO.setName("颜明");//测试环境也需要提供正式的四要素信息
        apiAddWorkerDTO.setPhone("15099990637");//测试环境也需要提供正式的四要素信息
        apiAddWorkerDTO.setIdCardCode("430422199604270000");//测试环境也需要提供正式的四要素信息
        //性别 ( 男 传 MAN, 女 传 WOMAN   )
        apiAddWorkerDTO.setSex("MAN");
        apiAddWorkerDTO.setBankCode("6214851203618397");//测试环境也需要提供正式的四要素信息


        //非必填参数
//        apiAddWorkerDTO.setTaxId(1559017216475664386L);
//        apiAddWorkerDTO.setIdCardBack("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        apiAddWorkerDTO.setIdCardFront("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        apiAddWorkerDTO.setContract("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        apiAddWorkerDTO.setContractNum("13132131221");
//        apiAddWorkerDTO.setAttestationPicture("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        apiAddWorkerDTO.setAttestationVideo("https://new-yyg.oss-cn-hangzhou.aliyuncs.com/upload/1/20221226/c8854dd04f164b1daf9218925a80f803.png");
//        apiAddWorkerDTO.setSkill("吃饭睡觉打豆豆");
//        apiAddWorkerDTO.setAddress("湖南省衡阳市********");

        //参与加密的参数    固定的几个字段缺一不可
        Map<String, Object> signMap = new HashMap<>(6);
        signMap.put("agentId", apiAddWorkerDTO.getAgentId());
        signMap.put("timestamp", apiAddWorkerDTO.getTimestamp());
        signMap.put("creditCode", apiAddWorkerDTO.getCreditCode());
        signMap.put("taxId", apiAddWorkerDTO.getTaxId());
        signMap.put("idCardCode", apiAddWorkerDTO.getIdCardCode());
        signMap.put("key", CommonUtil.KEY);

        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
        System.out.println(sign);
        apiAddWorkerDTO.setSign(sign);

        //请求地址
        String url = String.format(addWorkerPath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);
        String post = HttpUtil.post(url, JSON.toJSONString(apiAddWorkerDTO));
        System.out.println(post);


    }

    /**
     * 查询创客合同
     */
    public static void getWorkerAgreement() {
        ApiWorkerAgreementDTO apiWorkerAgreementDTO = new ApiWorkerAgreementDTO();
        apiWorkerAgreementDTO.setAgentId(CommonUtil.AGENT_ID);
        apiWorkerAgreementDTO.setTimestamp(System.currentTimeMillis());
        apiWorkerAgreementDTO.setCreditCode(CommonUtil.creditCode);
        //合同类型("WORKER_JOIN_AGREEMENT", "创客-平台的加盟协议")  ,  ("TAX_WORKER_AGREEMENT", "创客-服务商的承揽协议")
        apiWorkerAgreementDTO.setAgreementType("WORKER_JOIN_AGREEMENT");
        apiWorkerAgreementDTO.setIdCardCode("430422199604270000");  //测试环境也需要提供正式的四要素信息

        //非必填参数
//        apiWorkerAgreementDTO.setTaxId(1559017216475664386L);


        //参与加密的参数    固定的几个字段缺一不可
        Map<String, Object> signMap = new HashMap<>(6);
        signMap.put("agentId", apiWorkerAgreementDTO.getAgentId());
        signMap.put("timestamp", apiWorkerAgreementDTO.getTimestamp());
        signMap.put("creditCode", apiWorkerAgreementDTO.getCreditCode());
        signMap.put("idCardCode", apiWorkerAgreementDTO.getIdCardCode());
        signMap.put("key", CommonUtil.KEY);

        String sign = ApiSignUtil.getSign(JSON.parseObject(JSON.toJSONString(signMap)));
        System.out.println(sign);
        apiWorkerAgreementDTO.setSign(sign);

        //请求地址
        String url = String.format(getWorkerAgreementPath, CommonUtil.REQUEST_URL);
        System.out.println("请求地址： " + url);
        String post = HttpUtil.post(url, JSON.toJSONString(apiWorkerAgreementDTO));
        System.out.println(post);

    }


}